package com.AAL.DAO;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IActionOnStockDAO;
import com.AAL.Model.ActionOnStock;
import com.AAL.Utils.HibernateUtil;

public class ActionOnStockDAO implements IActionOnStockDAO {

	@Override
	public ActionOnStock getActionOnStock(int id) {
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			ActionOnStock actionOnStock = (ActionOnStock) session.load(
					ActionOnStock.class, (short)id);
			return actionOnStock;
			
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("Loi ham getActionOnStock:"+e.getMessage());
			return null;
		}
	
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ActionOnStock> getAllLstActionOnStock() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<ActionOnStock> lstActionOnStocks = null;
		try {

			lstActionOnStocks = (List<ActionOnStock>) session.createQuery(
					"from ActionOnStock").list();
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return lstActionOnStocks;
	}

}
